package com.zxkj.commonpatrol.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.czy.basecommon.utils.base.BaseRepository;
import com.czy.basecommon.utils.base.BaseViewModel;
import com.czy.basecommon.utils.base.StateLiveData;
import com.zxkj.commonpatrol.model.entity.SelectProjectEntrity;
import com.zxkj.commonpatrol.model.response.InspectionDetailResponse;
import com.zxkj.commonpatrol.repoisity.ProjectCheckPointListRepoisity;
import com.zxkj.commonpatrol.repoisity.ProjectListRepoisity;

import java.util.ArrayList;
import java.util.List;

public class ProjectCheckPointListViewModel extends BaseViewModel<ProjectCheckPointListRepoisity> {
    public StateLiveData<List<SelectProjectEntrity>> data=new StateLiveData<>();
    public StateLiveData<List<InspectionDetailResponse.InspectPoint>> CheckPonints=new StateLiveData<>();
    public ObservableField<String> a=new ObservableField<>("0");
    public ObservableField<String>b=new ObservableField<>("0");
    public ObservableField<String>c=new ObservableField<>("0");
    public ProjectCheckPointListViewModel(@NonNull Application application) {
        super(application);
    }


    public void  getSelectData(int type){
        mRepository.getSelectProject(type,new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                List<SelectProjectEntrity> da=(List<SelectProjectEntrity>)o;
                if (da==null){
                    da=new ArrayList<>();
                }
                data.postSuccess(da);

            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {

            }
        });
    }

    public  void  getCheckList(String RouteInspectNo,String Filter,int Categoryid,int PageSize,int PageIndex){
        mRepository.getCheckList(RouteInspectNo, Filter, Categoryid, PageSize, PageIndex, new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                if (o!=null){
                    InspectionDetailResponse  response=(InspectionDetailResponse)o;
                    List<InspectionDetailResponse.InspectPoint> points = response.getPoints();
                    if (points==null){
                        points=new ArrayList<>();
                    }
                    CheckPonints.postSuccess(points);
                    a.set(response.getPointStatisInfo().Pending+"");
                    b.set(response.getPointStatisInfo().Completed+"");
                    c.set(response.getPointStatisInfo().All+"");
                }
            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {
                CheckPonints.postFailure(404,(String)t1);
            }
        });
    }

}
